//  PULSAR, THE GAME
//  ================================
//  COPYRIGHT(c) 2013 BY KAMIL MRZYGŁÓD
//  CODENOVA.PL

define(['./Core'], function (Core) {
    var Viewport = function(objViewport) {
        this.ElementType = 'viewport';
        this.Elements = [];
        this.Height = objViewport.Height;
        this.Id = objViewport.Id;
        this.Name = objViewport.Name;
        this.Width = objViewport.Width;
    };

    Viewport.prototype = {
        Add: function() {
            var _i, _elements;

            // Draw all Viewport elements
            for(_i = 0, _elements = this.Elements.length - 1; _i <= _elements; _i = _i + 1) {
                this.Elements[_i].Add();
            }
        },

        Create: function(objViewport) {
            return new Viewport(objViewport);
        },

        Initialize: function() {
            var _i, _elements;

            // Create canvas for Viewport
            Core.CreateHtmlElement('canvas', {
                'data-id': this.Id,
                'data-element-type': this.ElementType,
                'height': this.Height,
                'width': this.Width
            });

            // Initialize Viewport elements
            for(_i = 0, _elements = this.Elements.length - 1; _i <= _elements; _i = _i + 1) {
                this.Elements[_i].Initialize();
            }
        },

        RegisterElement: function(el) {
            // Define Id for element
            Object.defineProperty(el, 'Id', {
                value: this.Id,
                writable: false,
                enumerable: true,
                configurable: false
            });

            // Push element to Elements array
            this.Elements.push(el);
        }
    };

    return Viewport.prototype.Create;
});